# coding:utf8

from flask import Blueprint, render_template, request, json, jsonify
from models.entity.module import Module

mod = Blueprint("home_system", __name__, url_prefix="/system", template_folder="templates", static_folder="static")


# @mod.route("/module", methods=["GET"])
# def module_list(*args, **kargs):
#     mid = Module.query.all()
#     #return render_template("home/module_list.html", **locals())
#     tmp = []
#     for m in mid:
#         tmp.append(m.to_dict())
#     return jsonify(tmp)

@mod.route("/module", methods=["GET"])
def module_index(*args, **kargs):
    title = "系统模块管理"
    return render_template("home/module.html", **locals())


@mod.route("/module/getmodulelist", methods=["GET"])
def module_list(*args, **kargs):
    pid = request.args.get("pid", default=0)
    print(11, pid)
    tmp = {'total': 0, 'rows': []}
    rs = Module().get_list_pid(pid)     # 没有get_list_pid(pid)方法
    print(22, rs)
    tmp['total'] = len(rs)
    for m in rs:
        tmp['rows'].append(m.to_dict())
    return jsonify(tmp)
